//
// Created by antler on 2018/10/30.
//
#include "lprefix.h"

#include "lua.hpp"
#include "luaext.hpp"

LUAMOD_API int (luaopen_common)(lua_State *L);

LUAMOD_API int (luaopen_color3b)(lua_State *L);

LUAMOD_API int (luaopen_color3f)(lua_State *L);

LUAMOD_API int (luaopen_point)(lua_State *L);

LUAMOD_API int (luaopen_rect)(lua_State *L);

LUAMOD_API int (luaopen_size)(lua_State *L);

LUAMOD_API int (luaopen_runtime)(lua_State *L);

LUAMOD_API int (luaopen_screen)(lua_State *L);

LUAMOD_API int (luaopen_image)(lua_State *L);

LUAMOD_API int (luaopen_script)(lua_State *L);

LUAMOD_API int luaopen_storage(lua_State *L);

LUAMOD_API int luaopen_task(lua_State *L);

LUAMOD_API int luaopen_touch(lua_State *L);

LUAMOD_API int luaopen_ui(lua_State *L);

LUAMOD_API int luaopen_xmod(lua_State *L);

static const lua_CFunction loadedfuncs[] = {
        luaopen_common,
        luaopen_color3b,
        luaopen_color3f,
        luaopen_point,
        luaopen_rect,
        luaopen_size,
        luaopen_runtime,
        luaopen_screen,
        luaopen_image,
        luaopen_script,
        luaopen_storage,
        luaopen_task,
        luaopen_touch,
        luaopen_ui,
        luaopen_xmod,
};

LUALIB_API void luaL_openextlibs(lua_State *L) {
    lua_getglobal(L, "_G");
    if (lua_istable(L, -1)) {
        for (const auto f : loadedfuncs) {
            lua_pushcfunction(L, f);
            lua_call(L, 0, 0);
        }
    }
    lua_pop(L, 1);
}